<?php

namespace App\Http\Controllers\Admin;

use App\Http\Resources\HomeResource;
use App\Http\Services\Admin\FailedJobsService;
use App\Http\Services\Admin\JobsService;
use Illuminate\Http\Request;

class JobsController
{

    public function statistics(Request $request, JobsService $service)
    {
        return HomeResource::success($service->statistics());
    }

    public function running(Request $request, JobsService $service)
    {
        $params = $request->input('params', []);
        array_push($params, [['attempts', '=', 0]]);
        $request->offsetSet('params', $params);

        return $service->make($request->input())->get();

    }

    public function retrying(Request $request, JobsService $service)
    {
        $params = $request->input('params', []);
        array_push($params, [['attempts', '>', 0]]);
        $request->offsetSet('params', $params);

        return $service->make($request->input())->get();

    }

    public function failed(Request $request, FailedJobsService $service)
    {
        return $service->make($request->input())->get();
    }
}
